package xiegd.com.springbootuse.demo;

import java.math.BigDecimal;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2022/7/12 15:33
 */
public class MyBigdecimalTest {
    public static void main(String[] args) {
        BigDecimal b = new BigDecimal("10.12004");
        //包含五位的小数
        BigDecimal fiveBig = b.setScale(5,BigDecimal.ROUND_DOWN);
        System.out.println("我是五位小数值：：" + fiveBig);

        BigDecimal fourBig = fiveBig.setScale(4, BigDecimal.ROUND_HALF_UP);
        System.out.println("我是四舍五入的小数值：：" + fourBig);

        BigDecimal twoBig = b.setScale(2,BigDecimal.ROUND_DOWN);
        System.out.println("我是二位的小数值：：" + twoBig);
        BigDecimal resultBig = new BigDecimal(twoBig.toString());
        //四舍五入的大,则加0.01
        if(fourBig.compareTo(twoBig) ==  1){
            resultBig =  resultBig.add(new BigDecimal("0.01"));
        }
        System.out.println("我是结果啊：：：" + resultBig);
    }
}
